package com.yao.zhihudaily.client;

import com.yao.zhihudaily.utils.CommonUtils;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by dell on 2015/6/2.
 * 向知乎日报应用的列表和文章Json获取提供公用接口
 * 未提取公用方法
 */
public class ClientAPI {
    /**
     * 返回当前最新的文章Json对象，包含日期 标题 图片
     * @return Json对象
     */
    public static JSONObject getLastStories(){
        JSONObject ret = null;
        StringBuilder sb = new StringBuilder("http://news-at.zhihu.com/api/4/stories/latest");
        String url = sb.toString();
        String jsonStr = CommonUtils.doGet(url);
        try {
            ret = new JSONObject(jsonStr);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return ret;
    }


    /**
     * 返回扉页图片Json 应写入缓存防止多次读取重复图片
     * @return
     */
    public static JSONObject getStartImage(){
        JSONObject ret = null;
        StringBuilder sb = new StringBuilder("http://news-at.zhihu.com/api/4/start-image/1080*1776");
        String url = sb.toString();
        String jsonStr = CommonUtils.doGet(url);
        try {
            ret = new JSONObject(jsonStr);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return ret;
    }


}
